import React from 'react';
import { navigate } from 'utils/router';
import { Nav } from '@teamix/ui';
import { getFeature } from 'utils/features';
import ProTag from 'components/proTag';
import TagForFeature from 'components/tagForFeature';
import intl from '../../../../../../locale';
export default class settingsNav extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      // needNoticeKeys: [
      //   'settings.repository_permissions',
      //   'settings.group_permissions',
      //   'settings.customize',
      //   'settings.security',
      // ],
    };
  }

  onConfirmBeforeLeave = (destination) => {
    navigate(destination);
    // if (!this.state.needNoticeKeys.includes(this.props.activeKey)) {
    //   navigate(destination);
    //   return;
    // }
    // Dialog.alert({
    //   title: '确定离开此页面',
    //   onOk: () => {
    //     navigate(destination);
    //   },
    // });
  };

  render() {
    const { planType } = this.props;
    return (
      <React.Fragment>
        <Nav selectedKeys={this.props.activeKey} embeddable defaultOpenAll {...this.props}>
          <Nav.Group
            maxCount={9}
            label={intl.get({
              id: 'code-assets.pages.settings.nav.GeneralSettings',
              defaultMessage: '通用设置',
            })}
          >
            <Nav.Item key="settings.repository_permissions">
              <a
                onClick={() => {
                  this.onConfirmBeforeLeave('/settings/repository_permissions');
                }}
              >
                {intl.get({
                  id: 'code-assets.pages.settings.nav.CodeLibrarySettings',
                  defaultMessage: '代码库设置',
                })}
              </a>
            </Nav.Item>
            <Nav.Item key="settings.group_permissions">
              <a
                onClick={() => {
                  this.onConfirmBeforeLeave('/settings/group_permissions');
                }}
              >
                {intl.get({
                  id: 'code-assets.pages.settings.nav.CodeGroupSettings',
                  defaultMessage: '代码组设置',
                })}
              </a>
            </Nav.Item>
            <Nav.Item key="settings.admins">
              <a
                onClick={() => {
                  this.onConfirmBeforeLeave('/settings/admins');
                }}
              >
                {intl.get({
                  id: 'code-assets.pages.settings.nav.AdministratorSettings',
                  defaultMessage: '管理员设置',
                })}
              </a>
            </Nav.Item>
            <Nav.Item key="settings.customize">
              <a
                onClick={() => {
                  this.onConfirmBeforeLeave('/settings/customize');
                }}
              >
                {intl.get({
                  id: 'code-assets.pages.settings.nav.EnterprisePersonalization',
                  defaultMessage: '企业个性化',
                })}
              </a>
            </Nav.Item>
          </Nav.Group>
          <Nav.Group
            maxCount={9}
            label={intl.get({
              id: 'code-assets.pages.settings.nav.SecurityCenter',
              defaultMessage: '安全中心',
            })}
          >
            {getFeature('page_enable.org.setting.security_center') && (
              <Nav.Item key="settings.security_center">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/security_center');
                  }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.SecurityOverview',
                    defaultMessage: '安全总览',
                  })}
                </a>
              </Nav.Item>
            )}
            {getFeature('page_enable.org.setting.member_behavior_security') && (
              <Nav.Item key="settings.member_behavior_security">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/member_behavior_security');
                  }}
                  style={{ display: 'block' }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.MemberBehaviorSecurity',
                    defaultMessage: '成员行为安全',
                  })}
                  <ProTag planType={planType} />
                </a>
              </Nav.Item>
            )}
            {getFeature('page_enable.org.setting.code_content_security') && (
              <Nav.Item key="settings.code_content_security">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/code_content_security');
                  }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.CodeContentSecurity',
                    defaultMessage: '代码内容安全',
                  })}
                </a>
              </Nav.Item>
            )}
            {getFeature('page_enable.org.setting.ip_address_whitelist') && (
              <Nav.Item key="settings.security">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/security');
                  }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.IpAddressWhitelist',
                    defaultMessage: 'IP 白名单',
                  })}
                </a>
              </Nav.Item>
            )}

            {getFeature('page_enable.org.setting.security_notification') && (
              <Nav.Item key="settings.security_notify">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/security_notify');
                  }}
                  style={{ display: 'block' }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.SecurityNotification',
                    defaultMessage: '安全通知',
                  })}
                  <ProTag planType={planType} />
                </a>
              </Nav.Item>
            )}

            <Nav.Item key="settings.audit">
              <a
                onClick={() => {
                  this.onConfirmBeforeLeave('/settings/audit');
                }}
              >
                {intl.get({
                  id: 'code-assets.pages.settings.nav.AuditLogs',
                  defaultMessage: '审计日志',
                })}
              </a>
            </Nav.Item>
            {getFeature('page_enable.org.setting.code_backup') && (
              <Nav.Item key="settings.repository_back_up">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/repository_back_up');
                  }}
                  style={{ display: 'block' }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.CodeBackup',
                    defaultMessage: '代码备份',
                  })}
                  <TagForFeature
                    type="primary"
                    size="small"
                    style={{ marginLeft: 8 }}
                    tagText="BETA"
                  />
                </a>
              </Nav.Item>
            )}
            {getFeature('module_enable.org.repository_encryption') && (
              <Nav.Item key="settings.encryption">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/encryption');
                  }}
                  style={{ display: 'block' }}
                >
                  {intl.get({
                    id: 'code-assets.pages.settings.nav.RepositoryEncryption',
                    defaultMessage: '仓库加密',
                  })}
                  <TagForFeature
                    type="primary"
                    size="small"
                    style={{ marginLeft: 8 }}
                    tagText="BETA"
                  />
                </a>
              </Nav.Item>
            )}
          </Nav.Group>
          <Nav.Group
            maxCount={9}
            label={intl.get({
              id: 'code-assets.pages.settings.nav.Extension',
              defaultMessage: '扩展',
            })}
          >
            {getFeature('page_enable.org.setting.webhook') && (
              <Nav.Item key="settings.organization_web_hook">
                <a
                  onClick={() => {
                    this.onConfirmBeforeLeave('/settings/organization_web_hook');
                  }}
                  style={{ display: 'block' }}
                >
                  Webhooks
                </a>
              </Nav.Item>
            )}
          </Nav.Group>
        </Nav>
      </React.Fragment>
    );
  }
}
